const express = require('express');
const app = express();

//指定动态视图的模板引擎用ejs
app.set('view engine', 'ejs');
//指定ejs页面的目录
app.set('views', './views');

const products = [{
    id: 1,
    name: 'AAA',
    price: 1212
},
{
    id: 2,
    name: 'BBB',
    price: 2323
},
{
    id: 3,
    name: 'CCC',
    price: 3434
}

];

app.get('/products', (req, res) => {
    //渲染模板
    res.render('test', { username: 'admin', products });
})

//服务监听
app.listen('8989', () => {
    console.log('服务器启动: http://localhost:8989');
})